package com.kuke.kukeuser.config;

import okhttp3.ConnectionPool;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;


/**
 *  191656 替换默认通信组件
 *  OpenFeign默认使用java自己带的URLConnetion对象创建HTTP请求
 *  作为OpenFeign目前默认支持Apache HttpClient与OKHttp两款产品
 */
@Configuration
public class OkHttpClientConfiguration {
    //2.kuke191656 spring ioc容器初始化时构件okHttpClient对象
    @Bean
    public okhttp3.OkHttpClient okHttpClient(){
        return new okhttp3.OkHttpClient.Builder()
                //读取超时时间
                .readTimeout(10, TimeUnit.SECONDS)
                //连接超时时间
                .connectTimeout(10, TimeUnit.SECONDS)
                //写超时时间
                .writeTimeout(10, TimeUnit.SECONDS)
                //设置连接池
                .connectionPool(new ConnectionPool())
                .build();
    }
}
